local skel = fk.CreateSkill {
  name = "emo__maochong",
}

skel:addEffect(fk.TargetConfirmed, {
  anim_type = "defensive",
  times = function (self, player)
    return 1 - player:usedSkillTimes(skel.name, Player.HistoryTurn)
  end,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(skel.name) and not player:isKongcheng()
    and player:usedSkillTimes(skel.name, Player.HistoryTurn) == 0
    and data.from and player ~= data.from and not data.from:isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askToDiscard(player, {
      max_num = 9999, min_num = 1, skill_name = skel.name, include_equip = false, cancelable = true, skip = true,
      prompt = "#emo__maochong-discard:"..data.from.id
    })
    if #cards > 0 then
      event:setCostData(self, {cards = cards, tos = {data.from}})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setEmotion(player, "./packages/moepack/image/anim/emo__maochong")
    local cards = event:getCostData(self).cards
    local from = data.from
    room:throwCard(cards, skel.name, player, player)
    if from:isNude() or from.dead then return end
    cards = table.random(from:getCardIds("he"), #cards)
    from:addToPile("$emo__maochong_pile", cards, false, skel.name)
  end,
})

skel:addEffect(fk.EventPhaseEnd, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return #player:getPile("$emo__maochong_pile") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:obtainCard(player, player:getPile("$emo__maochong_pile"), false, fk.ReasonJustMove, player, skel.name)
  end,
})

Fk:loadTranslationTable{
  ["emo__maochong"] = "猫虫",
  [":emo__maochong"] = "每回合限一次，每当你成为其他角色使用牌的目标后，你可以弃置任意数量的手牌，将其随机等量张牌扣置武将牌上，当前阶段结束时令其获得。",
  ["#emo__maochong-discard"] = "猫虫：你可以弃置任意数量的手牌，吃掉 %src 等量的牌",
  ["$emo__maochong_pile"] = "猫虫",

  ["$emo__maochong1"] = "（惊叫声）",
  ["$emo__maochong2"] = "（提示声）",
}


return skel
